package service

import (
	"encoding/json"
	"takeout/server/global"
	"takeout/server/internal/model/dao"
	"time"
)

func SyncRedis(name string) (dao.Merchant, error) {

	var merchant dao.Merchant
	if err := global.DB.Where("name  = ?", name).First(&merchant).Error; err != nil {
		return dao.Merchant{}, err
	}
	marshal, err := json.Marshal(merchant)
	if err != nil {
		return dao.Merchant{}, err
	}
	key := "merchantInfo"
	global.Rdb.Set(key, marshal, time.Minute*60)
	return merchant, nil
}
